<template>
	<view class="enterprise_zone_center">
		<view class="zqs-open-head">
			<uni-nav-bar left-icon="left" color="#ffffff" backgroundColor="transparent" :statusBar="!0" :border="!1">
				<block slot="left">
					<image class="left_back" :src="$util.img('upload/uniapp/xxjk/back_black_icon@2x.png')"
						@click="$util.goBack()">
					</image>
				</block>
			</uni-nav-bar>
		</view>
		<view class="head-view"
			:style="{backgroundImage:'url('+$util.img('upload/uniapp/xxjk/enterprise_zone_head_bg@2x.png')+')'}">
			<view class="title-box">
				<text class="title_text">千润源</text>
				<text class="title_text red">创业区</text>
			</view>
			<view class="title-dec">享分红额度 · 赚分红值</view>
			<view class="head-main">
				<view class="main-half">
					<view class="main-num">{{headDict.bonus_amount}}</view>
					<view class="main-num-dec">累计分红额度</view>
					<view class="main-but left" @click="$util.redirectTo('/pages/order/list/list')">我的订单</view>
				</view>
				<view class="main-half">
					<view class="main-num">{{headDict.surplus_bonus_amount}}</view>
					<view class="main-num-dec">剩余分红额度</view>
					<view class="main-but right" @click="$util.redirectTo('/xxjk/bonus/bonusCenter')">分红中心</view>
				</view>
			</view>
		</view>
		<view class="list-box" v-if="list.length > 0">
			<view class="list-item" v-for="(item,index) in list" :key="index" @click="toDetail(item.sku_id)">
				<image class="img" :src="$util.img(item.goods_image)"></image>
				<view class="item_content">
					<view class="good-name">{{item.goods_name}}</view>
					<view class="goods-dec">{{item.introduction}}</view>
					<view class="tips-box">
						<view class="tips-item" v-if="Number(item.dividends) > 0">赠{{item.dividends}}分红值</view>
						<view class="tips-item" v-if="Number(item.bonus_amount) > 0">享{{item.bonus_amount}}分红额度</view>
					</view>
					<view class="price-box">
						<text class="unit">￥</text>
						<text class="price-c">{{item.price}}</text>
					</view>
				</view>
			</view>
			<!-- <view class="down-tips" v-if="isNoMore">------到底了------</view> -->
		</view>
		<view class="list-box" v-else>
			<ns-empty :isIndex="!1" :fixed="!1" text="暂无数据"></ns-empty>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				list: [],
				headDict: {},

				page: 1,
				page_size: 10,
				count: 0,
				isNoMore: false,
			};
		},
		onShow() {
			if (!uni.getStorageSync('token')) {
				this.$util.redirectTo('/otherpages/login/login/login', {
					back: '/xxjk/enterprise_zone/index/index'
				}, 'redirectTo');
			}
			this.getHeadDict();
			this.upCallback();
		},
		onPullDownRefresh() {
			this.page = 1;
			this.list = [];
			this.isNoMore = false;
			this.getHeadDict();
			this.upCallback();
		},
		onReachBottom() {
			if (this.list.length >= this.count) {
				this.isNoMore = true;
			} else {
				this.page++;
				this.upCallback();
			}
		},
		methods: {
			/* 获取商品列表 */
			upCallback() {
				this.$api.sendRequest({
					url: '/goldpoints/api/Goods/page',
					data: {
						page: this.page,
						page_size: this.page_size,
					},
					success: res => {
						if (res.code == 0) {
							let arr = res.data.list;
							this.count = res.data.count;
							if (this.page == 1) {
								this.list = [];
								this.list = arr;
							} else {
								this.list = this.list.concat(arr);
							}
							uni.stopPullDownRefresh();
						} else {
							uni.stopPullDownRefresh();
						}
					},
					fail: res => {
						uni.stopPullDownRefresh();
					}
				})
			},
			/* 获取头部信息 */
			getHeadDict() {
				this.$api.sendRequest({
					url: '/goldpoints/api/Record/bouns',
					success: res => {
						if (res.code == 0) {
							this.headDict = res.data;
						}
					}
				})
			},
			//跳转商品详情
			toDetail(skuId) {
				this.$util.redirectTo('/pages/goods/detail/detail', {
					sku_id: skuId
				})
			}
		}
	}
</script>

<style lang="scss">
	page {
		// background-color: #FFF2EE;
	}

	.zqs-open-head {
		position: fixed;
		z-index: 9999;
	}

	.left_back {
		width: 48rpx;
		height: 48rpx;
	}

	.enterprise_zone_center {
		background-color: #FFF2EE;
		height: auto;
		// height: 100%;

		.head-view {
			// margin-top: 60rpx;
			width: 100vw;
			height: 780rpx;
			background-size: cover;
			padding: 188rpx 26rpx 0 26rpx;
			box-sizing: border-box;
			position: absolute;

			.title-box {
				.title_text {
					font-family: Source Han Sans CN, Source Han Sans CN;
					font-weight: 800;
					font-size: 68rpx;
					color: #333333;
					line-height: 80rpx;
				}

				.red {
					color: #FC311A;
				}
			}

			.title-dec {
				font-family: PingFang SC, PingFang SC;
				font-weight: 400;
				font-size: 28rpx;
				color: #777777;
				line-height: 50rpx;
			}

			.head-main {
				position: absolute;
				bottom: 122rpx;
				left: 26rpx;
				width: calc(100vw - 52rpx);
				display: flex;
				align-items: center;

				.main-half {
					width: 50%;
					display: flex;
					align-items: center;
					flex-direction: column;

					.main-num {
						font-family: Helvetica, Helvetica;
						font-weight: bold;
						font-size: 52rpx;
						color: #FFFFFF;
						line-height: 50rpx;
					}

					.main-num-dec {
						font-family: PingFang SC, PingFang SC;
						font-weight: 400;
						font-size: 24rpx;
						color: rgba(255, 255, 255, 0.6);
						line-height: 50rpx;
					}

					.main-but {
						margin-top: 34rpx;
						width: 256rpx;
						height: 72rpx;
						display: flex;
						align-items: center;
						justify-content: center;

						font-family: PingFang SC, PingFang SC;
						font-weight: 500;
						font-size: 28rpx;
						line-height: 50rpx;
					}

					.left {
						border-radius: 120rpx 120rpx 120rpx 120rpx;
						border: 2rpx solid #FFEBD3;
						color: #FFEBD3;
					}

					.right {
						background: #FFEBD3;
						border-radius: 120rpx 120rpx 120rpx 120rpx;
					}
				}
			}
		}

		.list-box {
			position: absolute;
			left: 24rpx;
			right: 24rpx;
			top: 746rpx;

			.list-item {
				background: #FFFFFF;
				border-radius: 24rpx 24rpx 24rpx 24rpx;
				padding: 24rpx 24rpx 28rpx 24rpx;
				margin-bottom: 20rpx;
				display: flex;
				justify-content: space-between;

				.img {
					height: 196rpx;
					min-width: 196rpx;
					max-width: 196rpx;
					border-radius: 16rpx;
				}

				.item_content {
					margin-left: 24rpx;
					width: 100%;

					.good-name {
						font-family: PingFang SC, PingFang SC;
						font-weight: 500;
						font-size: 32rpx;
						color: #222222;
						line-height: 50rpx;

						// overflow: hidden;
						// word-break: break-all;
						// /* break-all(允许在单词内换行。) */
						// text-overflow: ellipsis;
						// /* 超出部分省略号 */
						// display: -webkit-box;
						// /** 对象作为伸缩盒子模型显示 **/
						// -webkit-box-orient: vertical;
						// /** 设置或检索伸缩盒对象的子元素的排列方式 **/
						// -webkit-line-clamp: 2;
						// /** 显示的行数 **/
					}

					.goods-dec {
						margin-top: 8rpx;
						font-family: PingFang SC, PingFang SC;
						font-weight: 400;
						font-size: 24rpx;
						color: #777777;
						line-height: 28rpx;
					}

					.tips-box {
						margin-top: 16rpx;
						display: flex;
						flex-wrap: wrap;

						.tips-item {
							margin-right: 8rpx;
							margin-bottom: 8rpx;
							padding: 4rpx 16rpx;
							background: #FFEBD3;
							border-radius: 4rpx 4rpx 4rpx 4rpx;
							font-family: PingFang SC, PingFang SC;
							font-weight: 400;
							font-size: 20rpx;
							color: #793112;
							line-height: 23rpx;
						}
					}

					.price-box {
						margin-top: 20rpx;

						.unit {
							font-family: PingFang SC, PingFang SC;
							font-weight: 500;
							font-size: 24rpx;
							color: #FC311A;
							line-height: 50rpx;
						}

						.price-c {
							font-family: PingFang SC, PingFang SC;
							font-weight: 500;
							font-size: 36rpx;
							color: #FC311A;
							line-height: 50rpx;
						}
					}
				}
			}
		}

		.down-tips {
			margin: 48rpx 0;
			text-align: center;
			font-family: PingFang SC, PingFang SC;
			font-weight: 400;
			font-size: 24rpx;
			color: #777777;
			line-height: 28rpx;
		}
	}
</style>